'''
5.3.4 使用Pandas实现Excel数据过滤
'''

import pandas as pd

def score_50_to_90(a):
    return 50 <= a < 90

def age_20_to_30(a):
    return 20 <= a < 30

peoples = pd.read_excel('pandas4.xlsx', index_col='ID')
# 检查peoples DataFrame中是否有NaN
print(peoples.isnull().any())
# 清除NaN的行
peoples.dropna(inplace=True)
print(peoples)
# 分数及格的女性（大于等于60分）
pass_womans = peoples[(peoples['性别'] == 'F') & (peoples['分数']>=60)]
print(pass_womans)

# 50分至90分之间的20到30岁的男性
mans_50_to_90 = peoples[peoples['性别'] == 'M'].loc[peoples['分数'].apply(score_50_to_90)].loc[peoples['年龄'].apply(age_20_to_30)]
print(mans_50_to_90)